from create_import import *
from table_list import *


def create_service_impl(table: str):
    """
    创建service
    """
    _current = "service"
    param = Params(table)
    _class_name = (
        param.class_name_basic + _current[0].upper() + _current[1::] + "Impl"
    )  # 当前类名
    _class_name_mapper = "I" + param.class_name_basic + "Mapper"  # 当前类名
    _class_name_service = "I" + param.class_name_basic + "Service"  # 当前类名

    _package_name = f"package {param.package_name_basic}.{_current}.impl;"  # 当前包名

    _java_output_path = (
        f"{param.output_java_path_basic}/{_current}/impl"  # java文件路径
    )

    # print(f">>输出路径{_java_output_path}")
    if not os.path.exists(_java_output_path):
        os.makedirs(_java_output_path)

    _java_output_file = f"{_java_output_path}/{_class_name}.java"

    _print_output = output(_java_output_file)  # print 的output

    def printf(val):
        print(val, file=_print_output)

    demoblock = f"""{_package_name}

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import {param.package_name_basic}.entity.{param.class_name_basic};
import {param.package_name_basic}.mapper.{_class_name_mapper};
import {param.package_name_basic}.service.{_class_name_service};

@Service
public class {_class_name} extends ServiceImpl<{_class_name_mapper},{param.class_name_basic}> implements {_class_name_service} {'{'}

    """
    printf(demoblock)  # import block

    printf("}")
    # print(f"{param.table}创建{_current} impl - 完成")
    print(f'"{_package_name[_package_name.find(" ")+1 : -1 :]}"', end=",")


if __name__ == "__main__":
    for table in table_list:
        create_service_impl(table)
        # break
